#ifndef CSGCONTROLLER_H
#define CSGCONTROLLER_H

#include <QString>
#include <QFile>
#include <QTextStream>
#include <QRegExp>
#include <queue>
#include <map>
#include <utility>
#include <CGAL/Simple_cartesian.h>
#include <GL/gl.h>
#include "hebuilder.cpp"
#include "csgtree.h"
#include "MarchingTetrahedrons.h"
#include "camera.h"

typedef CGAL::Simple_cartesian<double>          K;
typedef K::Vector_3                             Vector_3;

class CSGController
{
public:
    CSGTree m_csgTree;
    vector<TRIANGLE> m_vTriangles; //Triangles which are result of the marching cubes algorithm
    Poly m_poly;

    CSGController();
    void readCSGFile(QString fileName);

    //Methods to form the polygon soup
    long int calcIsoSurface(XYZ originPoint , int dims[3] , double spacing[3]);
    void addTriangles(const TRIANGLE *aTriangles , int iNumTri ,  vector<TRIANGLE> &vTriangles);

    //Methods to form and render the half-edge structure
    void constructPoly();
    void calcPolyNormals();
    void drawPoly(int iTriangleType , bool bShowAll);
};

#endif // CSGCONTROLLER_H
